package com.lxx.wiki.controller;


import com.lxx.wiki.domain.req.UserLoginReq;
import com.lxx.wiki.domain.req.UserQueryReq;
import com.lxx.wiki.domain.req.UserSaveReq;
import com.lxx.wiki.domain.resp.CommonResp;
import com.lxx.wiki.domain.resp.UserQueryResp;
import com.lxx.wiki.service.UserService;
import jakarta.validation.Valid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    private static final Logger LOG = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService userService;


    @GetMapping("/all")
    public CommonResp all(@Valid UserQueryReq req) {
        CommonResp<List<UserQueryResp>> resp = new CommonResp<>();
        List<UserQueryResp> list = userService.list(req);
        resp.setContent(list);
        return resp;
    }

    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody UserSaveReq req) {
        userService.save(req);
        return new CommonResp<>();
    }

    @DeleteMapping("/del/{id}")
    public CommonResp delete(@PathVariable Long id) {
        CommonResp resp = new CommonResp<>();
        userService.delete(id);
        return resp;
    }




}
